package com.yunti.springboot.controller;

import com.yunti.springboot.annotation.Log;
import com.yunti.springboot.annotation.Permission;
import com.yunti.springboot.service.SubjectService;
import com.yunti.springboot.vo.Result;
import com.yunti.springboot.vo.req.ElectionSubjectReq;
import com.yunti.springboot.vo.req.GetSubjectReq;
import com.yunti.springboot.vo.req.SubjectReq;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/subject")
public class SubjectController {


    @Resource
    private SubjectService subjectService;

    @ResponseBody
    @PostMapping(value = "/getSubjectList")
    //通过页面大小、条数开始和结束时间对日志记录筛选
    public Result getSubjectList(@RequestBody GetSubjectReq getSubjectReq) {
        return subjectService.getSubjectByYear(getSubjectReq);
    }

    @ResponseBody
    @GetMapping(value = "/getAllSubject")
    //通过页面大小、条数开始和结束时间对日志记录筛选
    public Result getAllSubject() {
        return Result.success(subjectService.list());
    }

    //通过学期获取选科
    @ResponseBody
    @PostMapping(value = "/getSubList")
    public Result getSubList(@RequestBody ElectionSubjectReq req) {
        return subjectService.getSubList(req);
    }

    @ResponseBody
    @PostMapping(value = "/getAllSubBySemester")
    //通过页面大小、条数开始和结束时间对日志记录筛选
    public Result getAllSubBySemester(@RequestParam("semester") Integer semester) {
        return subjectService.getAllSubBySemester(semester);
    }

    @ResponseBody
    @PostMapping(value = "/page")
    public Result findPage(@RequestBody SubjectReq req) {
        return subjectService.findPage(req);
    }

    @Log
    @ResponseBody
    @Permission({"superAdmin"})
    @PostMapping(value = "/edit")
    public Result edit(@Validated(SubjectReq.edit.class) @RequestBody SubjectReq req) {
        return subjectService.edit(req);
    }

    @Log
    @ResponseBody
    @Permission({"superAdmin"})
    @PostMapping(value = "/add")
    public Result add(@Validated(SubjectReq.add.class) @RequestBody SubjectReq req) {
        return subjectService.add(req);
    }

    @Log
    @ResponseBody
    @Permission({"superAdmin"})
    @PostMapping(value = "/del")
    public Result del(@Validated(SubjectReq.del.class) @RequestBody SubjectReq req) {
        return subjectService.del(req);
    }
}
